#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:demo02.py
@time:2022/03/18
"""
import asyncio

import aiohttp


async def request(session,url):
    ...
    async with session.get(url) as response:
        ...
        return await response.text()

async def main():
    ...

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
                      "AppleWebKit/537.36 (KHTML, like Gecko)"
                      " Chrome/78.0.3904.108 Safari/537.36"
    }

    async with aiohttp.ClientSession(headers=headers) as session:
        ...
        # html = await request(session, "http://www.baidu.com/")
        # print(html)
        async with session.get("http://www.baidu.com") as response:
            html = await response.text()
            print(html)

if __name__ == '__main__':
    pass
    asyncio.run(main())